package cc.comac.mom.webservice.impl;

import java.util.HashMap;
import java.util.Map;

import javax.jws.WebService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cc.comac.mom.datahandlers.entity.QualityQarCheckInvoiceDataHandler;
import cc.comac.mom.datahandlers.entity.QualityQarConditionalSentMaterielDataHandler;
import cc.comac.mom.entity.QualityQarCheckInvoiceEntity;
import cc.comac.mom.entity.QualityQarConditionalSentMaterielEntity;
import cc.comac.mom.util.ResultBean;
import cc.comac.mom.webservice.QualityQarConditionalSentMaterielService;

@WebService(serviceName = "ConditionalSentMateriel", targetNamespace = "http://webservice.mom.comac.cc/", endpointInterface = "cc.comac.mom.webservice.QualityQarConditionalSentMaterielService")
@Service
public class QualityQarConditionalSentMaterielServiceImpl implements QualityQarConditionalSentMaterielService{

	@Autowired
	private QualityQarConditionalSentMaterielDataHandler QualityQarConditionalSentMaterielDataHandler;
	
	@Autowired
	private QualityQarCheckInvoiceDataHandler qualityQarCheckInvoiceDataHandler;
	// 有条件发料在进行发料后将QAR对应的PI信息发送给QAR系统
	@Override
	public String getPIDataFromConditionalSentMaterielPlatform(
			QualityQarConditionalSentMaterielEntity QualityQarConditionalSentMaterielEntity) {
		Map<String,String> map = new HashMap<String, String>();
		map.put("result", "true");
		map.put("message", "");
		ResultBean insertConditionalSentMateriel = QualityQarConditionalSentMaterielDataHandler.insertConditionalSentMateriel(QualityQarConditionalSentMaterielEntity);
		if (!insertConditionalSentMateriel.success) {
			map.put("result", "false");
			map.put("message", insertConditionalSentMateriel.getMessage());
			return map.toString();
		}
		return map.toString();
	}
	
	// 通过有条件发料系统提供的qar编号查询qar状态回传给有条件发料系统
	@Override
	public String selectQarStatusByQarNumber(String qarNumber) {
		Map<String,String> map = new HashMap<String, String>();
		map.put("qarNumber", qarNumber);
		map.put("status", "");
		map.put("result", "");
		map.put("message", "");
		QualityQarCheckInvoiceEntity selectByQarNumber = qualityQarCheckInvoiceDataHandler.selectByQarNumber(qarNumber);
		if (selectByQarNumber == null) {
			map.put("result", "false");
			map.put("message", "当前qar查询不到任何数据！");
			return map.toString();
		}
		map.put("status", selectByQarNumber.getStatus());
		map.put("result", "true");
		return map.toString();
	}
	
}
